package main

import (
	"encoding/json"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Response struct {
	msg  interface{}
	Code uint32
	data interface{}
}

const (
	GGGG = 90500
)

func functionB() {
	var (
		err  error
		code int
	)
	str := `{"code":90500,"msg":"系统错误[081012]：NSQ: Publish error "dial tcp: i/o timeout"","data":{}}`
	str = strings.TrimRight(strings.TrimLeft(str, "{"), "}")
	strTemp := strings.Split(str, ",")
	for _, vv := range strTemp {
		if strings.EqualFold(`"code"`, strings.Split(vv, ":")[0]) {
			code, err = strconv.Atoi(strings.TrimSpace(strings.Split(vv, ":")[1]))
			if err != nil {
				fmt.Println("err occur:", err.Error())
				os.Exit(-1)
			} else {
				break
			}
		}
	}
	if code == GGGG {
		fmt.Println("code:", code)
	}

}


//type Response struct {
//	msg  interface{}
//	Code uint32
//	data interface{}
//}
func functionA() {
	response := &Response{}

	str := `{"code":90500,"msg":"系统错误[081012]：NSQ: Publish error "dial tcp: i/o timeout"","data":{}}`
	res, _ := strconv.Atoi(strings.Split(strings.Split(str, ",")[0], ":")[1])
	fmt.Println("res:", res)
	//str := "{\"code\":10000,\"msg\":\"用户没有登录\",\"data\":{}}"
	//str := `{"code":10000,"msg":"用户没有登录","data":{}}`
	fmt.Println("str:", str)
	err := json.Unmarshal([]byte(str), response)
	if err != nil {
		fmt.Println("err occur:", err.Error())
		return
	}
	fmt.Println("response:", response)
}


func functionC(){
	type Point struct {
		Lon int64 `json:Lon`
		Lat int64 `json:Lat`
	}
	type Result struct {
		Rings []Point `json:Rings`
	}
	result := &Result{}
	str := `{"Rings":[{"Lon":116132623,"Lat":43247578},{"Lon":116134397,"Lat":43243517}]}`
	fmt.Println("str:", str)
	err := json.Unmarshal([]byte(str), result)
	if err != nil {
		fmt.Println("err occur in functionC:",err.Error())
		return
	}
	for _,v := range result.Rings {
		fmt.Println("Lon:",v.Lon,",Lat:",v.Lat)
	}
	//fmt.Println("result:",result)
}
func main() {
	//	str := `{"code": 90500,"msg":"系统错误[081012]：NSQ: Publish error \"dial tcp: i/o timeout\"","data":{}}`
	//	res,err:= strconv.Atoi(strings.TrimSpace(strings.Split(strings.Split(str, ",")[0], ":")[1]))
	//	if err != nil{
	//		fmt.Println("err:",err)
	//	}
	//		fmt.Println("res:",res)
	//functionB()
	functionC()
}
